<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<!-- head 头部-->
<head th:replace="admin/layout/include::head('配置管理','')"></head>

<body>
<!-- loading 动画-->
<div th:replace="admin/layout/include::loading"></div>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">
                <div class="pull-left layui-form-pane search-box">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">搜索：</label>
                        <div class="layui-input-inline mr0">
                            <input id="edtSearch" class="layui-input" type="text" placeholder="输入关键字"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
                        <button id="btnAdd" shiro:hasPermission="config:add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                    </div>
                </div>
            </div>


            <!-- 数据表格 -->
            <table class="layui-table" id="data-table" lay-filter="data-table"></table>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="toolbarOepration">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-sm layui-btn-danger" ajax-event="batchDel" ajax-url="/admin/config/" ajax-id="configId">
            <i class="layui-icon layui-icon-delete"></i>批量删除</button>
    </div>
</script>
<!-- 表格操作列 -->
<script type="text/html" id="data-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" ajax-event="del" ajax-url="/admin/config/" value="{{d.configId}}">删除</a>
</script>
<!-- js部分 -->
<div th:replace="admin/layout/include::js"></div>
<script>
    layui.use(['form', 'table', 'util', 'admin'], function () {
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;

        var formUrl;  // 表单提交的action

        //渲染表格
        var tableIns = table.render({
            elem: '#data-table',
            url: '/admin/config/',
            page : true,
			loading : true,
			height : 'full-115',
            toolbar: '#toolbarOepration',
			limit : 10,
			limits : [ 10, 20, 50, 100 ],
            response:{
	        	countName: 'total'
	        },
            cols: [
                [
                {type: 'checkbox'},
                {field: 'configName', title: '配置名'},
                {field: 'configCode', sort: true, title: '配置编码'},
                {field: 'configType', sort: true, title: '配置域'},
                {field: 'configValue',title: '配置值'},
                {field: 'configDesc', title: '配置描述'},
                {
                    field: 'createTime', sort: true, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '创建时间'
                },
                {align: 'center', toolbar: '#data-table-bar', title: '操作'}
            ]
            ]
        });

        // 添加按钮点击事件
        $('#btnAdd').click(function () {
            showEditModel();
        });


        // 工具条点击事件
        table.on('tool(data-table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            }
        });

        // 搜索按钮点击事件
        $('#role-btn-search').click(function () {
            var keyword = $('#edtSearch').val();
            tableIns.reload( {where: {configName: keyword}},'data');
        });

        // 显示编辑弹窗
        var showEditModel = function (data) {
            admin.putTempData("t_config",data);
            admin.putTempData("formOk",false);
            top.layui.admin.open({
                type: 2,
                title: data ? '修改配置' : '添加配置',
                area: ['500px', '520px'],
                content: '/admin/config/save',
                end: function () {
                    admin.getTempData('formOk') && tableIns.reload({},'data');  // 成功刷新表格
                }
            });

        };


    });

</script>
</html>